package io;

import java.io.FileWriter;
import java.io.IOException;

/**
 * Created by pc on 2015/4/29.
 */
public class FileWriterTest {
    public static void main(String[] args) throws IOException {
        FileWriter writer = new FileWriter("D://poem.txt");
        try{
            writer.write("锦瑟 - 李商隐\r\n");
            writer.write("锦瑟无端五十弦，一弦一柱思华年。\r\n");
            writer.write("庄生晓梦迷蝴蝶，望帝春心托杜鹃。\r\n");
            writer.write("沧海月明珠有泪，蓝田日暖玉生烟。\r\n");
            writer.write("此情可待成追忆，只是当时已惘然。\r\n");

        }catch (IOException err){
            err.printStackTrace();
        }finally {
            writer.close();
        }
        //java7 try-with-resource 用法
/*        try (
                FileWriter fw = new FileWriter("poem.txt")) {
            fw.write("锦瑟 - 李商隐\r\n");
            fw.write("锦瑟无端五十弦，一弦一柱思华年。\r\n");
            fw.write("庄生晓梦迷蝴蝶，望帝春心托杜鹃。\r\n");
            fw.write("沧海月明珠有泪，蓝田日暖玉生烟。\r\n");
            fw.write("此情可待成追忆，只是当时已惘然。\r\n");
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }*/
    }
}

